<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/head.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台管理工作平台</title>
<script type="text/javascript" src="<%=basePath%>/js/check.js"></script>
</head>
<body>
<form action="" name="form1" id="form1" method="post">
  	<table>
  		<tr>
  			<td>用户名:</td>
  			<td><input type="text" name="emp.account" id="account" value="<s:property value="emp.account"/>"/></td>
  		</tr>
  		<tr >
	  		<td></td>
	  		<td><span id="accountmessage"></span></td>
  		</tr>
  		<tr>
  			<td>密码:</td>
  			<td><input type="password" name="emp.pwd" id="password" value="<s:property value="emp.pwd"/>"/></td>
  		</tr>
  		<tr>
  			<td>确认密码:</td>
  			<td><input type="password"  id="conword"/></td>
  		</tr>
  		<tr>
  			<td>真实姓名:</td>
  			<td><input type="text" name="emp.username" id="username" value="<s:property value="emp.pwd"/>"/></td>
  		</tr>
  		<tr>
  			<td>性别:</td>
  			<td><input type="radio"  name="emp.sex" id="sex" value="1" <s:if test="emp== null || emp.sex==1">checked="true"</s:if> />男<input type="radio"  name="emp.sex" id="sex" value="2" <s:if test="emp.sex==2">checked="true"</s:if>/>女</td>
  		</tr>
  		<tr>
  			<td>电话:</td>
  			<td><input type="text" name="emp.linktel" id="linktel" value="<s:property value="emp.linktel"/>"/></td>
  		</tr>
  		<tr>
  			<td>工作:</td>
  			<td><input type="text" name="emp.job" id="job" value="<s:property value="emp.job"/>"/></td>
  		</tr>
  		<tr>
  			<td>Email:</td>
  			<td><input type="text" name="emp.email" id="email" value="<s:property value="emp.email"/>"/></td>
  		</tr>
  		<tr>
  			<td>手机:</td>
  			<td><input type="text" name="emp.mobile" id="mobile" value="<s:property value="emp.mobile"/>"/></td>
  		</tr>
  		<tr>
  			<td>角色:</td>
  			<td>
  			<select name="emp.roseid" id="roseid">
	  			<s:iterator value="list" status="status">
	  				<option value="<s:property value="id"/>" <s:if test="emp.roseid==id">selected="true"</s:if> ><s:property value="rolename"/></option>
	  			</s:iterator>
  			</select>
  			</td>
  		</tr>
  		<tr>
  			<td>是否管理员:</td>
  			<td>
  			<select  name="emp.ismanager" id="ismanager">
  			<option value="1">是</option>
  			<option value="0">否</option>
  			</select>
  			</td>
  		</tr>
  		<tr>
  			<td>备注:</td>
  			<td><textarea name="emp.des" id="des"><s:property value="emp.des"/></textarea></td>
  		</tr>
  		<tr>
  		<td colspan="2" align="center">
  			<input type="button" id="subform" value="提交"/>&nbsp;&nbsp;<input type="reset" value="重置"/></td>
  		</tr>
  	</table>
  	<input type="hidden" name="emp.id" id="empid" value="<s:property value="emp.id"/>"/>
  	</form>
</body>
</html>
<script type="text/javascript">
<!--
	//提交
	$("#subform").click(function() {
		if (checkform()) {
			var content = "";
			var url = "";
			var empid = $("#empid").val();
			if (empid > 0) {
				url = "updateemp.do";
			} else {
				empid = 0;
				url = "saveemp.do";
			}
			//序 列化表格元素 (类似 '.serialize()' 方法) 返回 JSON 数据结构数据
			content = $("#form1").serializeArray();
			$.post(url, content, function(data) {
				if (data == 1) {
					alert("保存失败！");
					location = "";
				} else {
					alert("保存成功！");
					location = "";
				}
			}, "json");
		}
	});

	/**
	 * 检查form
	 */
	function checkform() {
		var account = $("#account").val();
		var password = $("#password").val();
		var conword = $("#conword").val();
		var username = $("#username").val();
		var linktel = $("#linktel").val();
		var job = $("#job").val();
		var email = $("#email").val();
		var roseid = $("#roseid").val();
		var ismanager = $("#ismanager").val();
		var des = $("#des").val();
		var sex = $("#sex").val();
		var mobile = $("#mobile").val();
		var empid = $("#empid").val();
		if (account == "" || accountflag == 1) {
			alert("帐号为空或帐号已经存在");
			return false;
		}
		if (password == "") {
			alert("密码不能为空");
			return false;
		}
		if (conword == "") {
			alert("确认密码不能为空");
			return false;
		}
		if (password != conword) {
			alert("确认密码不正确");
			return false;
		}
		if (username == "") {
			alert("真实名称不能为空");
			return false;
		}
		if (linktel == "") {
			alert("联系电话不能为空");
			return false;
		}
		if (mobile == "" || !isMobile(mobile)) {
			alert("手机格式不正确！");
			return false;
		}
		/*
		if(job ==""){
			alert("工作单位不能为空");
			return false;
		}
		 */
		if (email == "" || !isEmail(email)) {
			alert("邮箱地址格式不正确！");
			return false;
		}
		if (roseid == "") {
			alert("请选择角色");
			return false;
		}
		return true;
	}

	
	var accountflag = 0;
	/**
	检查帐号是否存在 
	*/
	$("#account").blur(function() {
		var account = $("#account").val();
		if (account == "") {
			$("#accountmessage").html("");
			$("#accountmessage").html("帐号不能为空");
			return false;
		}
		$.getJSON("checkemp.do", {
			account : account
		}, function(data) {
			if (data == 1) {
				$("#accountmessage").html("");
				$("#accountmessage").html("帐号已经存在，请重新填写帐号");
				accountflag = 1;
			} else {
				accountflag = 0;
				$("#accountmessage").html("");
				$("#accountmessage").html("帐号不存在，可以添加");
			}
		});
	});
	//-->
</script>
